home *** CD-ROM | disk | FTP | other *** search
/ SuperHack / SuperHack CD.bin / CODING / DEMOS / TRIAD.ZIP / OUTLAW.ASM < prev    next >
Encoding:
Assembly Source File  |  1996-04-14  |  12.8 KB  |  434 lines

  1.  
  2. ; ▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓ INFO ▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓
  3. ;
  4. ;       Better write some info on this source...
  5. ;
  6. ;       An Outlaw Triad intro. Introduces the Outlaw Triad team.
  7. ;       Coded in 100% assembler and in high resolution 640*480*16.
  8. ;       Fully commented but knowledge of vga programming is required.
  9. ;
  10. ;       Major thanks go to Troop / Chiparus / Outlaw Triad! I couldn't
  11. ;       have made this without his help. Design was done by him. Thanks!
  12. ;
  13. ;       Characters are written to the screen using the Bit Mask register.
  14. ;       Thus, only 16 MOV commands are needed to write the character to
  15. ;       the screen which makes it pretty fast. Man, it sure was hard to
  16. ;       code this stringwriter. I think it is up for major improvement.
  17. ;       It's way too complex to my taste but well, I got it to work. But
  18. ;       if you see a way to improve it, please do! In fact, this intro
  19. ;       can be optimized quite a lot, me thinks... :-)
  20. ;
  21. ;       If you decide to use this, go ahead. But don't just change the
  22. ;       text and release it again. That would be lame. Instead, use this
  23. ;       to learn. And, greet Outlaw Triad in your future productions.
  24. ;       That's all. Is that cheap or what? :-)
  25. ;
  26. ;         Feel like chatting? E-mail me at: comma400@tem.nhl.nl
  27. ;
  28. ;           Later,
  29. ;
  30. ;             -Vulture / Outlaw Triad-
  31. ;
  32. ; ▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓
  33.  
  34. DOSSEG              ; Sort segment like high level languages do
  35. .MODEL SMALL        ; Code & data seperate segments, both < 64kB & near
  36. .STACK 200h         ; 512 byte stack
  37. .286                ; Allow 286 instructions
  38. .DATA               ; Datasegment starts here (empty)
  39. .CODE               ; Codesegment starts here (code & data in codesegment)
  40. JUMPS               ; Let tasm handle out of range jumps
  41.  
  42. ASSUME cs:@code;ds:@code        ; Let cs and ds point to code segment
  43.  
  44. ; ▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓ Various data ▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓
  45.  
  46. INCLUDE Text.dat                ; Text to show
  47. INCLUDE Pal.dat                 ; Palette data
  48.  
  49. Label Credits Byte
  50.      DB 13,10,"▄  ▄▄  ▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄  ▄▄  ▄"
  51.      DB 13,10,"                    - An Outlaw Triad Production (c) 1996 -",13,10
  52.      DB 13,10,"                             Code∙∙∙∙∙∙∙∙∙∙Vulture" ,13,10
  53.      DB 13,10,"                            -=≡ Outlaw Triad is ≡=-",13,10
  54.      DB 13,10,"         Vulture(code) ■ Dazl(artist) ■ Troop(sysop) ■ Xplorer(artist)",13,10
  55.      DB 13,10,"▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄",13,10,"$"
  56.  
  57. Font_Seg  DW    0               ; Font segment
  58. Font_Off  DW    0               ; Font offset in segment
  59.  
  60. Xsize     EQU   1               ; 1 byte (8 pixels)
  61. Ysize     EQU   16              ; 16 bytes
  62.  
  63. TextPos   EQU   80*108          ; Y position of text
  64.  
  65. CharColor DB    15              ; Color of char (what else, eh? ;-) )
  66. Char_Off  DW    0               ; Which char to start with
  67. Char_X    DW    0
  68. Char_Y    DW    TextPos
  69. NewChar_X DW    0
  70. NewChar_Y DW    0
  71.  
  72. ; ▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓ Code 'n stuff ▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓
  73.  
  74. WaitVrt PROC NEAR               ; Waits for vertical retrace to reduce "snow"
  75.     mov     dx,3dah
  76. Vrt:
  77.     in      al,dx
  78.     test    al,1000b
  79.     jnz     Vrt                 ; Wait until Verticle Retrace starts
  80. NoVrt:
  81.     in      al,dx
  82.     test    al,1000b
  83.     jz      NoVrt               ; Wait until Verticle Retrace ends
  84.     ret                         ; Return to main program
  85. WaitVrt ENDP
  86.  
  87. ResetRGB PROC NEAR              ; Resets number of colors to black
  88.     mov     cx,16*3             ; Number of colors (16)
  89.     mov     dx,03c8h            ; Write register
  90.     xor     al,al               ; Start at 0
  91.     out     dx,al               ; Write to port
  92.     inc     dx                  ; Data register 03c9h
  93.     xor     al,al
  94. ResetLoop:
  95.     out     dx,al
  96.     loop    ResetLoop
  97.     ret
  98. ResetRGB ENDP
  99.  
  100. FadeUp PROC NEAR
  101.     mov     cx,64                ; Range from 0..63
  102. OuterRGB:
  103.     xor     si,si                ; Real colors
  104.     xor     bx,bx                ; Fading colors
  105.     push    cx
  106.     mov     cx,16*3              ; Do # colors
  107. InnerRGB:
  108.     mov     ah,[Palette+si]      ; Load real value
  109.     mov     al,[EmptyPalette+bx] ; Load fading value
  110.     cmp     al,ah                ; Compare
  111.     je      NextRGB
  112.     inc     al
  113.     mov     [EmptyPalette+bx],al
  114. NextRGB:
  115.     inc     si
  116.     inc     bx
  117.     loop    InnerRGB
  118.  
  119.     call    WaitVrt
  120.  
  121.     lea     si,EmptyPalette
  122.     mov     dx,03c8h
  123.     xor     al,al
  124.     out     dx,al
  125.     inc     dx
  126.     mov     cx,16*3             ; 16 colors (shayded)
  127. RGBLoop1:
  128.     lodsb
  129.     out     dx,al
  130.     loop    RGBLoop1            ; Using a loop is saver than "rep outsb"
  131.  
  132.     pop     cx
  133.     loop    OuterRGB            ; Next run (for 0..63 rgb values)
  134.     ret
  135. FadeUp ENDP
  136.  
  137. FadeDown PROC NEAR
  138.     mov     cx,64                ; Range from 0..63
  139. OuterRGB2:
  140.     xor     si,si                ; Real colors
  141.     xor     bx,bx                ; Fading colors
  142.     push    cx
  143.     mov     cx,16*3              ; Do # colors
  144. InnerRGB2:
  145.     mov     ah,[EmptyPalette+si] ; Load real value
  146.     cmp     ah,0                 ; Compare
  147.     je      NextRGB2
  148.     dec     ah
  149.     mov     [EmptyPalette+bx],ah
  150. NextRGB2:
  151.     inc     si
  152.     inc     bx
  153.     loop    InnerRGB2
  154.  
  155.     call    WaitVrt
  156.  
  157.     lea     si,EmptyPalette
  158.     mov     dx,03c8h
  159.     xor     al,al
  160.     out     dx,al
  161.     inc     dx
  162.     mov     cx,16*3              ; 16 colors (shayded)
  163. RGBLoop2:
  164.     lodsb
  165.     out     dx,al
  166.     loop    RGBLoop2             ; Using a loop is saver than "rep outsb"
  167.  
  168.     pop     cx
  169.     loop    OuterRGB2            ; Next run (for 0..63 rgb values)
  170.     ret
  171. FadeDown ENDP
  172.  
  173. SetColor PROC NEAR              ; Needs: cx=color (0 to 15)
  174.     mov     dx,3ceh             ; Graphic Controller address register port
  175.     mov     ax,0f01h            ; Index 01h  (enable set/reset register)
  176.     out     dx,ax
  177.     xor     al,al               ; Index 00h  (set/reset register)
  178.     mov     ah,cl               ; Color (0 to 15)
  179.     out     dx,ax               ; Set color
  180.     ret
  181. SetColor ENDP
  182.  
  183. TestEsc PROC NEAR
  184.     in      al,60h              ; Was ESCAPE pressed ?
  185.     cmp     al,1
  186.     je      QuitNow             ; Yes => quit now. . .
  187.     ret
  188. TestEsc ENDP
  189.  
  190. WaitHere PROC NEAR              ; Simple waitroutine
  191.     mov     cx,250
  192. WaitLoop:
  193.     call    WaitVrt
  194.     call    TestEsc             ; Check for escape
  195.     loop    WaitLoop
  196.     ret
  197. ENDP WaitHere
  198.  
  199. SetLines PROC NEAR
  200.     mov     cx,10               ; Color of lines
  201.     call    SetColor
  202.     mov     dx,3ceh             ; Graphic Controller address register port
  203.     mov     ah,0ffh
  204.     mov     al,08h
  205.     out     dx,ax
  206.     mov     al,ah
  207.     mov     di,(80*45)+5
  208.     mov     cx,70
  209.     rep     stosb
  210.     mov     di,(80*47)+5
  211.     mov     cx,70
  212.     rep     stosb
  213.     mov     di,(80*435)+5
  214.     mov     cx,70
  215.     rep     stosb
  216.     mov     di,(80*437)+5
  217.     mov     cx,70
  218.     rep     stosb
  219.     ret
  220. SetLines ENDP
  221.  
  222. DeleteText PROC NEAR            ; Guess what this does, eh?  :-)
  223.     xor     cx,cx
  224.     call    SetColor            ; Set background color
  225.     mov     di,80*50
  226.     mov     cx,80
  227. HoriLoop:
  228.     push    di
  229.     mov     al,0ffh
  230.     mov     bx,380              ; # of scanlines
  231. VertiLoop:
  232.     mov     byte ptr es:[di],al
  233.     add     di,80               ; Next scanline
  234.     dec     bx
  235.     jnz     VertiLoop
  236.     pop     di
  237.     inc     di                  ; Next position
  238.     call    WaitVrt
  239.     loop    HoriLoop
  240.     ret
  241. DeleteText ENDP
  242.  
  243. WriteChar PROC NEAR
  244.     push    ds
  245.  
  246. ; === Select the char ===
  247.     mov     ds,[Word Ptr cs:Font_Seg]
  248.     mov     si,[Word Ptr cs:Font_Off]   ; ds:[si] => offset to font
  249.     xor     dx,dx               ; Empty dx
  250.     mov     dl,al               ; dl=char to print
  251.     shl     dx,4                ; *16 (number of bytes per char)
  252.     add     si,dx               ; ds:[si] points to chardata
  253.  
  254. ; === Set color of char ===
  255.     mov     dx,3ceh             ; Graphic Controller address register port
  256.     mov     ax,0f01h            ; Index 01h  (enable set/reset register)
  257.     out     dx,ax
  258.     xor     al,al               ; Index 00h  (set/reset register)
  259.     mov     ah,CharColor        ; Color (0 to 15)
  260.     out     dx,ax               ; Set color
  261.  
  262. ; === Draw the char ===
  263.     mov     cx,Ysize            ; If bit=0, don't draw
  264. YLiner:
  265.     mov     al,08h              ; Index 08h (Bit Mask Register)
  266.     mov     ah,byte ptr ds:[si] ; Load the pattern (8 bits)
  267.     out     dx,ax               ; Pattern selected (if bit=1 then it's drawn)
  268.     mov     al,byte ptr es:[di] ; Dummy read from vga
  269.     mov     byte ptr es:[di],ah ; Draw scanline
  270.     add     di,80               ; Next scanline (draw scanline twice)
  271.     mov     al,byte ptr es:[di]
  272.     mov     byte ptr es:[di],ah
  273.     add     di,80
  274.     inc     si
  275.     loop    YLiner
  276.  
  277.     pop     ds
  278.     ret
  279. WriteChar ENDP
  280.  
  281. WriteText PROC NEAR             ; Kinda complex writer... but it works :-)
  282. StartWrite:
  283.     mov     si,offset Text1
  284.     add     si,Char_Off         ; Character offset
  285.     inc     Char_Off
  286.     mov     di,Char_Y
  287.     add     di,Char_X           ; VGA position
  288.     mov     CharColor,12
  289.  
  290.     lodsb                       ; Get char (from ds:[si])
  291.  
  292.     cmp     al,254              ; Reached end of line?
  293.     je      UpdatePos1
  294.     cmp     al,255
  295.     je      WaitNow
  296.     cmp     al,0                ; Reached end of da text?
  297.     jne     OkChar1             ; If not, do the char
  298.     call    WaitHere            ; Else reset intro
  299.     call    DeleteText
  300.     mov     Char_Off,0
  301.     mov     Char_X,0
  302.     mov     Char_Y,80*125
  303.     jmp     StartWrite
  304.  
  305. OkChar1:
  306.     push    si
  307.     call    WriteChar
  308.     pop     si
  309.     inc     Char_X
  310.     jmp     ShayedWrite
  311.  
  312. UpdatePos1:
  313.     mov     Char_X,0
  314.     add     Char_Y,80*(Ysize*2)
  315.     jmp     ShayedWrite
  316.  
  317. WaitNow:
  318.     call    WaitHere
  319.     call    DeleteText
  320.     mov     Char_X,0
  321.     mov     Char_Y,TextPos
  322.     jmp     StartWrite
  323.  
  324. ShayedWrite:
  325.     call    WaitVrt
  326.     call    TestEsc
  327.  
  328.     mov     ax,Char_X
  329.     mov     bx,Char_Y
  330.     mov     NewChar_X,ax
  331.     mov     NewChar_Y,bx        ; Switch X,Y values
  332.  
  333.     mov     CharColor,11
  334.     mov     cx,11
  335. MainWrite:
  336.     push    cx
  337.     mov     di,NewChar_Y
  338.     add     di,NewChar_X        ; VGA position
  339.     lodsb                       ; Get char (from ds:[si])
  340.     cmp     al,254              ; Reached end of line?
  341.     je      UpdatePos2
  342.     cmp     al,255
  343.     jne     LastCheck
  344.     pop     cx
  345.     jmp     StartWrite
  346. LastCheck:
  347.     cmp     al,0                ; Reached end of da text?
  348.     jne     OkChar2
  349.     pop     cx
  350.     jmp     StartWrite          ; Jump to start of writer !!!
  351.  
  352. OkChar2:
  353.     push    si
  354.     call    WriteChar
  355.     pop     si
  356.     dec     CharColor
  357.     inc     NewChar_X
  358.     jmp     Continue1
  359.  
  360. UpdatePos2:
  361.     mov     NewChar_X,0
  362.     add     NewChar_Y,80*(Ysize*2)
  363.  
  364. Continue1:
  365.     pop     cx
  366.     loop    MainWrite
  367.     jmp     StartWrite
  368.  
  369.     ret
  370. WriteText ENDP
  371.  
  372. ; ▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓ Main Program ▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓
  373.  
  374. START:
  375.  
  376.     mov     ax,cs
  377.     mov     ds,ax               ; ds points to codesegment
  378.  
  379. ; === Select the charset ===
  380.     mov     al,30h              ; Return seg/ofs on selected charset in BH
  381.     mov     ah,011h             ; Load character generator BIOS routines
  382.     mov     bh,06h              ; Select 8*16 characterset
  383.     int     10h
  384.     mov     Font_Seg,es         ; Return segment of charset
  385.     mov     Font_Off,bp         ; Return offset of charset
  386.  
  387. ; === Init vga ===
  388.     mov     ax,0012h            ; 640x480x16 vgamode
  389.     int     10h
  390.  
  391.     mov     ax,0a000h
  392.     mov     es,ax               ; es points to vga
  393.  
  394. ; === Palette setup (code by Iguana!) ===
  395.     mov     dx,3c0h        ; Create a Linear Palette instead of EGA-Palette
  396.     xor     al,al               ; Index 00h & data 00h
  397.     mov     cx,16
  398. LinPal:
  399.     out     dx,al               ; Output index.
  400.     out     dx,al           ; Out to vga => value = index
  401.     inc     al
  402.     loop    LinPal
  403.  
  404.     mov     al,34h          ; Redo it, activating the VGA along
  405.     out     dx,ax
  406.     xor     al,al
  407.     out     dx,al              ; Force DAC index bits p4-p7 to 0
  408.  
  409. ; === Setup screen ===
  410.     call    ResetRGB
  411.     call    SetLines
  412.     call    FadeUp
  413.  
  414. ; === Print text ===
  415.     lea     si,Text1
  416.     call    WriteText
  417.  
  418. ; === Back to DOS ===
  419. QuitNow:
  420.     call    FadeDown
  421.     mov     ax,0003h
  422.     int     10h                 ; Textmode
  423.     lea     dx,Credits
  424.     mov     ah,09h
  425.     int     21h                 ; Write string
  426.     mov     ax,4c00h
  427.     int     21h                 ; Return control to DOS
  428.  
  429. END START
  430.  
  431.  
  432.  
  433.  
  434. ; Code by Vulture / Outlaw Triad...